var source=1;
var is_bool={};
var is_change={};
var page_no={};

$(function(){
    var IpIntegralRule=document.querySelector('.IpIntegralRule')
    var modle=document.querySelector('.Model')
    IpIntegralRule.index=true
    IpIntegralRule.addEventListener('click',function(e){
        e.stopPropagation();
        if(IpIntegralRule.index){
            modle.className='Model Model-active'
            IpIntegralRule.index=!IpIntegralRule.index
        }else{
            return false
        }
    })
    modle.addEventListener('click',function(){
        if(!IpIntegralRule.index){
            modle.className='Model'
            IpIntegralRule.index=!IpIntegralRule.index
        }else{
            return false
        }
    })
    
    //初始化变量
    source=$('.record-tab-item').eq(0).attr('data-source');
    $('.record-tab-item').each(function(){
        var index=$(this).attr('data-source');
        is_bool['is_bool_'+index]=true;
        is_change['is_change_'+index]=true;
        page_no['page_no_'+index]=1;
    });

    //标签页切换
    $('.record-tab-item').click(function(){
        if(is_change['is_change_'+source]&&$(this).attr('data-source')!=source){
            $('.record-tab-item').removeClass('record-tab-item-active');
            $(this).addClass('record-tab-item-active');
            $('.record-box .record-box-item').css('left','100%').hide();
            $('.record-box .record-box-item').eq($(this).index()).show().animate({left:'0px'});
            source=$(this).attr('data-source');
        }
    });

    $('.record-tab-item').each(function(){
        getIntegralRecordList($(this).attr('data-source'));
    });
    

    //滚动到底
    $(window).scroll(function(){
    　　var scrollTop = $(this).scrollTop();
    　　var scrollHeight = $(document).height();
    　　var windowHeight = $(this).height();
    　　if(scrollTop + windowHeight == scrollHeight&&is_bool['is_bool_'+source]){
            getIntegralRecordList(source);
    　　}
    });
})

function getIntegralRecordList(func_source) {
    //禁止滚动,禁止切换
    is_bool['is_bool_'+func_source]=false;
    is_change['is_change_'+func_source]=false;


    $('.record-box-item-'+func_source).find('.load').show();
    $.ajax({
        type: "post",
        url: "Api/IntegralRecord/getIntegralRecordList",
        data: {
            park_id: $('#park_id').val(),
            admin_id:$('#admin_id').val(),
            source:func_source,
            page_no:page_no['page_no_'+func_source]
        },
        async: true,
        dataType: 'json',
        success: function(data) {
            setTimeout(function(){
                is_change['is_change_'+func_source]=true;
                $('.record-box-item-'+func_source).find('.load').hide();
                if (data.status) {
                    var t=JSON.parse(data.v);
                    $.each(t.data,function(k,v){
                        $('.record-demo').find('.integral-source').html(v.source_char);
                        $('.record-demo').find('.integral-time').html(v.created_char);
                        $('.record-demo').find('.integral').html(v.num);
                        $('.record-box-item-'+func_source).find('.load').before($('.record-demo').html());
                    });
                    is_bool['is_bool_'+func_source]=t.have;
                    page_no['page_no_'+func_source]=Number(page_no['page_no_'+func_source])+1;
                    if(!t.have){
                        $('.record-box-item-'+func_source).find('.no-data').show();
                    }
                    console.log(is_bool);
                    console.log(page_no);
                } else {

                }
            },1000);
        }
    });
}